﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Kinect;

namespace KinectPowerPointControl_sample1_Fukidashi
{

    enum FootHeight
    {
        High,   // HipCenter（腰）より上
        Middle  // Knee（膝）より上
    }

    static class ProcessKickGesture
    {
        static bool isKickGestureActive;
        static FootHeight footHeight;

        public static bool kickState(JointCollectionEquivalent joints)
        {

            if (getSkeleton(joints))
            {
                return false;
            }


            if (joints[JointType.FootLeft].Position.Y > joints[JointType.KneeRight].Position.Y + 0.15 ||
                joints[JointType.FootRight].Position.Y > joints[JointType.KneeLeft].Position.Y + 0.15)
            {
                //ハイキック判定時
                if(!isKickGestureActive){
                    footHeight = FootHeight.High;
                    isKickGestureActive = true;
                    return true;
                }
            } else if(  joints[JointType.FootLeft].Position.Y > joints[JointType.KneeRight].Position.Y ||
                        joints[JointType.FootRight].Position.Y > joints[JointType.KneeLeft].Position.Y){
                //ミドルキック、ソバット判定時
                if(!isKickGestureActive){
                    footHeight = FootHeight.Middle;
                    isKickGestureActive = true;
                    return true;
                }
            } else {
                isKickGestureActive = false;
            }

            return false;
        }
        
        public static FootHeight footHeightState(){
            return footHeight;
        }

        //判定に必要なジョイントが補足されていない場合Trueを返す
        private static bool getSkeleton(JointCollectionEquivalent joints)
        {
            if (joints[JointType.FootRight].TrackingState != JointTrackingState.Tracked ||
                joints[JointType.HandLeft].TrackingState != JointTrackingState.Tracked ||
                joints[JointType.HipCenter].TrackingState != JointTrackingState.Tracked ||
                joints[JointType.KneeRight].TrackingState != JointTrackingState.Tracked ||
                joints[JointType.KneeLeft].TrackingState != JointTrackingState.Tracked)
            {
                //Don't have a good read on the joints so we cannot process gestures
                return true;
            }
            return false;
        }
    }

}
